<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>批次暂停释放查询报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="'批次暂停释放查询报表'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules">
        <el-form-item label="主制分厂:" prop="factoryid">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择主制分厂" clearable filterable @change="bindControl">
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="主制工区:">
          <el-select v-model="queryInfo.workcenterid" placeholder="请选择主制工区" clearable filterable>
            <el-option v-for="item in workcenterList" :key="item.workcenterid" :label="item.workcentername"
              :value="item.workcenterid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="批次状态:">
          <el-select v-model="queryInfo.status" placeholder="请选择批次状态" clearable filterable>
            <el-option :key="'已释放'" :label="'已释放'" :value="'已释放'"></el-option>
            <el-option :key="'已暂停'" :label="'已暂停'" :value="'已暂停'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="批次是否关闭:">
          <el-select v-model="queryInfo.isclosed" placeholder="请选择" clearable filterable>
            <el-option :key="'已关闭'" :label="'已关闭'" :value="'已关闭'"></el-option>
            <el-option :key="'未关闭'" :label="'未关闭'" :value="'未关闭'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop='mfgordername' label="订单号:">
          <el-autocomplete v-model="queryInfo.mfgordername" placeholder="请输入订单号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchMfgorderAsync" :value-key="'mfgordername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='productname' label="零件图号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containername' label="流水卡号:">
          <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入流水卡号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="工艺员:">
          <el-select v-model="queryInfo.gongyiyuan" placeholder="请选择工艺员" clearable filterable>
            <el-option v-for="p in gongyiyuanList" :key="p.employeeid" :label="p.fullname" :value="p.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="推送时间:">
          <el-date-picker v-model="queryInfo.createdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="50" label="序号"></el-table-column>
        <el-table-column label="主制分厂" prop="factoryname" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="订单号" prop="mfgordername" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="流水卡号" prop="containername"></el-table-column>
        <el-table-column label="零件图号" prop="productname" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="零件名称" prop="productdescription" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="当前工序" prop="workflowstepname" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="批次类型" prop="containertype" width="80"></el-table-column>
        <el-table-column label="在制数" prop="qty" width="60"></el-table-column>
        <el-table-column label="批次当前状态" prop="ishold" width="85">
          <template slot-scope="scope" v-if="scope.row.ishold">
            <el-tag v-if="scope.row.ishold === '已暂停'" type="danger">{{scope.row.ishold}}</el-tag>
            <el-tag v-else type="success">{{scope.row.ishold}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="批次是否已关闭" prop="ishold" width="85">
          <template slot-scope="scope" v-if="scope.row.isclosed">
            <el-tag v-if="scope.row.isclosed === '已关闭'" type="danger">{{scope.row.isclosed}}</el-tag>
            <el-tag v-else type="success">{{scope.row.isclosed}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="暂停原因" prop="operreason" width="140" show-overflow-tooltip></el-table-column>
        <el-table-column label="推送时间" prop="createdate" width="150" :formatter="replaceDate"></el-table-column>
        <el-table-column label="主制工区" prop="fromworkcentername" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="工艺员" prop="fullname" width="60"></el-table-column>
        <el-table-column label="类型" prop="opertype" width="70">
          <template slot-scope="scope" v-if="scope.row.opertype">
            <el-tag v-if="scope.row.opertype === '暂停'" type="danger">{{scope.row.opertype}}</el-tag>
            <el-tag v-else type="success">{{scope.row.opertype}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="当前件号版本" prop="productrevision" width="60"></el-table-column>
        <el-table-column label="推送件号版本" prop="new_productrevision" width="60"></el-table-column>
        <el-table-column label="当前工艺版本" prop="workflowrevision" width="60"></el-table-column>
        <el-table-column label="推送工艺版本" prop="new_workflowrevision" width="60"></el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[12,50,100]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { getParams, fetchSuggestion, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getFactory, getFactoryUsersByRoleName, getWorkcenterList, getUserInfo } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { replaceDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        replaceDate,
        queryInfo: {
          factoryid: '',
          workcenterid: '',// 主制工区
          mfgordername: '',
          productname: '',
          containername: '',
          gongyiyuan: '',
          createdate: '',// 推送时间
          status: '已暂停',
          isclosed: '',
          currentPage: 1,//当前页
          pageSize: 12//每页显示条数
        },
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        dataList: [],
        factoryList: [], // 分厂列表
        gongyiyuanList: [],// 工艺员
        workcenterList: [],
        // 表单验证
        rules: { factoryid: [{ required: true, message: '主制分厂不能为空', trigger: 'change' }] },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 查询订单号
        searchMfgorderAsync(value, callback) {
          fetchSuggestion({ actionName: 'getMfgordernameAsync', name: 'mfgordername', value, callback });
        },
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback });
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback });
        },
        async bindControl(factoryid) {
          this.queryInfo.gongyiyuan = null;
          this.queryInfo.workcenterid = null;
          if (factoryid) {
            this.gongyiyuanList = await getFactoryUsersByRoleName({ factoryid, rolename: '工艺员' });
            this.workcenterList = await getWorkcenterList({ factoryid });
          }
        },
        //查询数据
        async getData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.loading = true
              this.loadingText = '数据加载中...'
              const { data: { data, meta, total } } = await axios.post('../handler/report/ContainerHoldOrReleaseReport.ashx?action=getData', {
                type: 'getData',
                ...this.queryInfo
              })
              this.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }
              this.dataList = data;
              this.total = total;
            }
          })
        },
        //导出excel
        async getExportExcel() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              const config = {
                url: '../handler/report/ContainerHoldOrReleaseReport.ashx?action=exportExcel',
                data: { type: 'exportExcel', ...this.queryInfo }
              }
              exportExcelData(config, this);
            }
          })
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        }
      },
      async mounted() {
        this.factoryList = await getFactory();
        const userInfo = await getUserInfo({ employeeid: getParams("uid") });
        const { factoryid } = this.factoryList.some(i => i.factoryid === userInfo.factoryid) ? userInfo : this.factoryList[0];
        this.queryInfo.factoryid = factoryid
        this.gongyiyuanList = await getFactoryUsersByRoleName({ factoryid, rolename: '工艺员' });
        this.workcenterList = await getWorkcenterList({ factoryid });
      },
      watch: { queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true } }
    })
  </script>
</body>

</html>